<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style>
td {font-size:12px;width:20;height:20}
table{table-layout:fixed}
body{cursor:default;margin:0;border:1px solid #000000}
</style>
<script>
	document.onselectstart	= function(){return false;}
	document.onmousedown	= start;
	document.onmouseup		= end;
	document.onmousemove	= move;

	window.onfocus			= resize;
	window.onblur			= kill;

	var drawEnable			= false;
	var curRows				= -1;
	var curCells			= -1;
	var parentObject		= null;
	var _jEditor			= null;

	function kill()
	{
		parentObject.parentElement.activeState	= false;
		parentObject.parentElement.buttonState	= 'out';
		parentObject.style.visibility			= 'hidden';
	}

	function start()
	{
		drawEnable			= true;
		curRows				= Math.ceil((event.clientX-2)/20)-1;
		curCells			= Math.ceil((event.clientY-2)/20)-1;
		selectTable();
		iTable.setCapture();
	}

	function end()
	{
		var x				= curRows+1;
		var y				= curCells+1;
		drawEnable			= false;
		curRows				= -1;
		curCells			= -1;
		selectTable();
		resetTable();
		resize();
		iTable.releaseCapture();

		var oldHtmlStr = _jEditor.editControl.DOM.selection.createRange().htmlText;
		var str				= '';
		str					+= '<table border="1" width="100%">';
		for(var i=0;i<y;i++)
		{
			str				+= '<tr>';
			for(var j=0;j<x;j++)
			{
				str			+= '<td>'+(i==0&&j==0?oldHtmlStr:'&nbsp;')+'</td>'
			}
			str				+= '</tr>';
		}
		str					+= '</table>';

		_jEditor.insertHTML(str,'',true);
		kill();
	}

	function move()
	{
		if(drawEnable==true)
		{
			if(event.clientX>iTable.offsetWidth || event.clientY>iTable.offsetHeight)
			{
				var dx		= Math.max(0,Math.ceil((event.clientX-iTable.offsetWidth)/20));
				var dy		= Math.max(0,Math.ceil((event.clientY-iTable.offsetHeight)/20));
				for(var i=0;i<iTable.rows.length;i++)
				{
					for(var j=0;j<dx;j++)
					{
						iTable.rows(i).appendChild(iTable.rows(i).cells(0).cloneNode(true));
					}
				}
				for(var i=0;i<dy;i++)
				{
					iTable.firstChild.appendChild(iTable.rows(0).cloneNode(true));
				}
				resize();
			}

			curRows		= Math.ceil((event.clientX-2)/20)-1;
			curCells	= Math.ceil((event.clientY-2)/20)-1;
			selectTable();

		}
	}

	function selectTable()
	{	
		back.style.width	= (curRows+1)*20;
		back.style.height	= (curCells+1)*20;
	}

	function resetTable()
	{
		var delRows		= iTable.rows.length-4;
		var delCells	= iTable.rows(0).cells.length-5;
		for(var i=0;i<delRows;i++)
		{
			iTable.deleteRow();
		}
		for(var i=0;i<4;i++)
		{
			for(var j=0;j<delCells;j++)
			{
				iTable.rows(i).deleteCell();
			}
		}
	}

	function resize()
	{	
		//parentObject				= parent.document.activeElement;
		parentObject.style.width	= iTable.offsetWidth+2;
		parentObject.style.height	= iTable.offsetHeight+2;
	}

	function public_init(e)
	{
		parentObject				= e;
		_jEditor					= parent.document.all(e.ancestor);
		self.focus();
	}
</script>
</HEAD>

<BODY>
<TABLE border=1 cellspacing=0 cellpadding=0 id=iTable>
<TR>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
</TR>
<TR>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
</TR>
<TR>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
</TR>
<TR>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
	<TD>&nbsp;</TD>
</TR>
</TABLE>
<div id=back style="background-color:highlight;width:0;height:0;position:absolute;z-index:-1;left:2;top:2;font-size:12px"></div>
</BODY>
</HTML>
